package cn.chenhuanming.shh.administer.entity.jpa;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.annotations.DynamicInsert;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * UserBroker entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "user_broker", catalog = "house")
@DynamicInsert
public class UserBroker implements java.io.Serializable {

	// Fields

	private String username;
	private UserSystem userSystem;
	private String password;
	private String name;
	private String phone;
	private String description;
	private String photo;
	private Integer integral;
	private Integer startLevel;
	private String isGold;
	private Set<House> houses = new HashSet<House>(0);
	private Set<EstateBroker> estateBrokers = new HashSet<EstateBroker>(0);
	private Set<Store> stores = new HashSet<Store>(0);
	private Set<InformationDispose> informationDisposes = new HashSet<InformationDispose>(
			0);
	private Set<HouseQualityApply> houseQualityAppliesForApplicant = new HashSet<HouseQualityApply>(
			0);
	private Set<HouseOrderApply> houseOrderApplies = new HashSet<HouseOrderApply>(
			0);
	private Set<HouseQualityApply> houseQualityAppliesForExaminer = new HashSet<HouseQualityApply>(
			0);

	private String managerName;
	// Constructors

	/** default constructor */
	public UserBroker() {
	}

	/** minimal constructor */
	public UserBroker(String username, UserSystem userSystem, String password,
			String name, String phone, Integer integral) {
		this.username = username;
		this.userSystem = userSystem;
		this.password = password;
		this.name = name;
		this.phone = phone;
		this.integral = integral;
	}

	/** full constructor */
	public UserBroker(String username, UserSystem userSystem, String password,
			String name, String phone, String description, String photo,
			Integer integral, Integer startLevel, String isGold,
			Set<House> houses, Set<EstateBroker> estateBrokers,
			Set<Store> stores, Set<InformationDispose> informationDisposes,
			Set<HouseQualityApply> houseQualityAppliesForApplicant,
			Set<HouseOrderApply> houseOrderApplies,
			Set<HouseQualityApply> houseQualityAppliesForExaminer) {
		this.username = username;
		this.userSystem = userSystem;
		this.password = password;
		this.name = name;
		this.phone = phone;
		this.description = description;
		this.photo = photo;
		this.integral = integral;
		this.startLevel = startLevel;
		this.isGold = isGold;
		this.houses = houses;
		this.estateBrokers = estateBrokers;
		this.stores = stores;
		this.informationDisposes = informationDisposes;
		this.houseQualityAppliesForApplicant = houseQualityAppliesForApplicant;
		this.houseOrderApplies = houseOrderApplies;
		this.houseQualityAppliesForExaminer = houseQualityAppliesForExaminer;
	}

	@Transient
	public String getManagerName() {
		return managerName;
	}

	public void setManagerName(String managerName) {
		this.managerName = managerName;
	}

	@PostLoad
	public void setManagerNamePost(){
		setManagerName(userSystem.getName());
	}

	// Property accessors
	@Id
	@Column(name = "username", unique = true, nullable = false, length = 20)
	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "manager", nullable = false)
	public UserSystem getUserSystem() {
		return this.userSystem;
	}

	public void setUserSystem(UserSystem userSystem) {
		this.userSystem = userSystem;
	}

	@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
	@Column(name = "password", nullable = false, length = 20)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "name", nullable = false, length = 20)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "phone", nullable = false, length = 20)
	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "description")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "photo")
	public String getPhoto() {
		return this.photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}

	@Column(name = "integral", nullable = false)
	public Integer getIntegral() {
		return this.integral;
	}

	public void setIntegral(Integer integral) {
		this.integral = integral;
	}

	@Column(name = "start_level")
	public Integer getStartLevel() {
		return this.startLevel;
	}

	public void setStartLevel(Integer startLevel) {
		this.startLevel = startLevel;
	}

	@Column(name = "is_gold", length = 2)
	public String getIsGold() {
		return this.isGold;
	}

	public void setIsGold(String isGold) {
		this.isGold = isGold;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userBroker")
	public Set<House> getHouses() {
		return this.houses;
	}

	public void setHouses(Set<House> houses) {
		this.houses = houses;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userBroker")
	public Set<EstateBroker> getEstateBrokers() {
		return this.estateBrokers;
	}

	public void setEstateBrokers(Set<EstateBroker> estateBrokers) {
		this.estateBrokers = estateBrokers;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userBroker")
	public Set<Store> getStores() {
		return this.stores;
	}

	public void setStores(Set<Store> stores) {
		this.stores = stores;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userBroker")
	public Set<InformationDispose> getInformationDisposes() {
		return this.informationDisposes;
	}

	public void setInformationDisposes(
			Set<InformationDispose> informationDisposes) {
		this.informationDisposes = informationDisposes;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userBrokerByApplicant")
	public Set<HouseQualityApply> getHouseQualityAppliesForApplicant() {
		return this.houseQualityAppliesForApplicant;
	}

	public void setHouseQualityAppliesForApplicant(
			Set<HouseQualityApply> houseQualityAppliesForApplicant) {
		this.houseQualityAppliesForApplicant = houseQualityAppliesForApplicant;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userBroker")
	public Set<HouseOrderApply> getHouseOrderApplies() {
		return this.houseOrderApplies;
	}

	public void setHouseOrderApplies(Set<HouseOrderApply> houseOrderApplies) {
		this.houseOrderApplies = houseOrderApplies;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userBrokerByExaminer")
	public Set<HouseQualityApply> getHouseQualityAppliesForExaminer() {
		return this.houseQualityAppliesForExaminer;
	}

	public void setHouseQualityAppliesForExaminer(
			Set<HouseQualityApply> houseQualityAppliesForExaminer) {
		this.houseQualityAppliesForExaminer = houseQualityAppliesForExaminer;
	}

}